import com.atguigu.gmall.realtime.bean.KeywordBean;

import java.lang.reflect.Field;

/**
 * @Author lzc
 * @Date 2023/1/6 14:21
 */
public class Demo3 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Class<KeywordBean> tClass = KeywordBean.class;
    
//        Field[] fields = tClass.getFields();  // 获取所有 public 的 field
       // Field[] fields = tClass.getDeclaredFields(); //获取所有 的 field
    
        /*String msg = "";
        for (Field field : fields) {
            msg += field.getName() + ",";
        }
        msg = msg.substring(0, msg.length() - 1);
        System.out.println(msg);*/
    
        /*String msg = Arrays.stream(fields)
            .map(f -> f.getName())
            .collect(Collectors.joining(","));
        System.out.println(msg);*/
    
        Field stt = tClass.getDeclaredField("stt");
        KeywordBean bean = new KeywordBean();
    
        stt.setAccessible(true);  // 给 stt 设置允许在外面访问
        stt.set(bean, "abc");  // bean.stt="abc"
    
        System.out.println(bean);
    
        Object o = stt.get(bean);
        System.out.println(o);
    
    
    }
}
